---
title: "Copartisanship and Partisanship Variations"
author: "Kaylyn Jackson Schiff, Daniel Schiff, and Natalia Bueno"
date: "2022"
output: pdf_document
editor_options: 
  chunk_output_type: console
---

#####Setup Chunk#####
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rmarkdown)
library(tidyverse)
library(gridExtra)
library(xtable)
library(stargazer)
library(estimatr)
library(regrrr)
library(dotwhisker)
library(interplot)
library(sandwich)
library(ggpubr)
library(meta)
library(RColorBrewer)
library(rstatix)
options(scipen=999)

base_dir <- getwd()
```


#####Figure A2: Figure 5 Results with Leaners Classified as Independents
#####Table B24: Figure 5 Regression Results - Leaners as Independents
#####Table B25: Figure 5 Regression Results - Leaners as Independents, Attentive
```{r all studies}
ld1 <- readRDS("data/df_clean.rds")
ld2 <- readRDS("data/df_followup_clean.rds")
ld4 <- readRDS("data/df_study4_clean.rds")
ld5 <- readRDS("data/df_study5_clean.rds")

#IU pooled
ld3_IU <- ld1 %>% filter(alleg_treatment != "Opp. Rally") %>% 
  mutate(wave = 1) %>% 
  dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) %>% 
  rbind(
    ld2 %>% filter(alleg_treatment_1 != "Fact Check") %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 2) %>% 
      dplyr::select(support = support_exp1, belief = belief_exp1, trust = trust_exp1, belief_1,
                    media_format, wave, alleg_treatment = alleg_treatment_1, partisan = partisan_1, partisan_lean = partisan_1_lean,
                    party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
    ) %>%
  rbind(
    ld4 %>% filter(alleg_treatment != "Opp. Rally") %>% 
  mutate(wave = 4) %>% 
  dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  ) %>%
  rbind(
    ld5 %>% filter(alleg_treatment != "Opp. Rally") %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 5) %>% 
      dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  )

#OR pooled
ld3_OR <- ld1 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
  mutate(wave = 1) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) %>% 
  rbind(
    ld2 %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 2) %>% 
      dplyr::select(support = support_exp2,
                    media_format, wave, alleg_treatment = alleg_treatment_2, partisan = partisan_2, partisan_lean = partisan_2_lean,
                    party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
    ) %>%
  rbind(
    ld4 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
  mutate(wave = 4) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  ) %>%
  rbind(
    ld5 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
      mutate(media_format = "Text") %>%
  mutate(wave = 5) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, party_3_lean, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  )

#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

iu_anti_att <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti_att <- iu_anti_att[2,]

or_anti_att <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti_att <- or_anti_att[2,]

iu_mod_att <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod_att <- iu_mod_att[2,]

or_mod_att <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod_att <- or_mod_att[2,]

iu_co_att <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co_att <- iu_co_att[2,]

or_co_att <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co_att <- or_co_att[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti,
                 iu_co_att, or_co_att, iu_mod_att, or_mod_att, iu_anti_att, or_anti_att)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan",
                   "Co-partisan Atttentive", "Co-partisan Attentive", "Independent Attentive", "Independent Attentive", "Out-partisan Attentive", "Out-partisan Attentive")
co_data$partisan <- rep(c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan"), 2)
co_data$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), 3), 2)
co_data$attentive <- rep(c("Full", "Attentive Only"), each = 6)

#Figure A2
pdf(file.path(base_dir, "Figures/pooled_copartisan_coefplot_all_studies.pdf"), width=7.5, height=4.5)

co_plot <- dwplot(co_data %>% arrange(partisan),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = partisan, shape = partisan)),
whisker_args = list(aes(linetype = attentive, color = partisan)))  +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"),
                        values = c(1,2),
                        na.translate = F) +
  scale_color_manual(name = "Partisanship", 
                   labels = c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   breaks=c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   values = c("#F8766D", "#00BA38", "#619CFF"),
                   na.translate = F) +
 scale_shape_manual(name = "Partisanship", 
                    labels = c("Co-partisan", "Independent", "Out-partisan"), 
                    breaks=c("Co-partisan", "Independent", "Out-partisan"),
                    values = c(15, 17, 16),
                    na.translate = F) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index by Co-partisanship") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
co_plot
dev.off()

#Table B24
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 Regression Results - Leaners as Independents",
          label="tab:fig_4_nolean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Studies 1, 2, 4, 5", "Studies 1, 2, 4, 5")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_all_studies_nolean.tex"))

#Table B25
IU_fig4 <- lm(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 Regression Results - Leaners as Independents, Attentive",
          label="tab:fig_4_attentive_nolean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Studies 1, 2, 4, 5 Att.", "Studies 1, 2, 4, 5 Att.")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_all_studies_attentive_nolean.tex"))

```

#Exploratory: Figure 5 for Republicans only
```{r fig 4 republicans}
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Republican") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Republican") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Republican") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Republican") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

iu_anti_att <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Republican") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti_att <- iu_anti_att[2,]

or_anti_att <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Republican") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti_att <- or_anti_att[2,]

iu_co_att <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Republican") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co_att <- iu_co_att[2,]

or_co_att <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Republican") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co_att <- or_co_att[2,]

co_data <- rbind(iu_co, or_co, iu_anti, or_anti,
                 iu_co_att, or_co_att, iu_anti_att, or_anti_att)
co_data$model <- c("Co-partisan", "Co-partisan", "Out-partisan", "Out-partisan",
                   "Co-partisan Atttentive", "Co-partisan Attentive", "Out-partisan Attentive", "Out-partisan Attentive")
co_data$partisan <- rep(c("Co-partisan", "Co-partisan", "Out-partisan", "Out-partisan"), 2)
co_data$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), 2), 2)
co_data$attentive <- rep(c("Full", "Attentive Only"), each = 4)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot <- dwplot(co_data %>% arrange(partisan),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = partisan, shape = partisan)),
whisker_args = list(aes(linetype = attentive, color = partisan)))  +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"),
                        values = c(1,2),
                        na.translate = F) +
  scale_color_manual(name = "Partisanship", 
                   labels = c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   breaks=c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   values = c("#F8766D", "#00BA38", "#619CFF"),
                   na.translate = F) +
 scale_shape_manual(name = "Partisanship", 
                    labels = c("Co-partisan", "Independent", "Out-partisan"), 
                    breaks=c("Co-partisan", "Independent", "Out-partisan"),
                    values = c(15, 17, 16),
                    na.translate = F) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index by Co-partisanship \n for Republicans") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
co_plot

```

#Exploratory: Figure 5 for Democrats only
```{r fig 4 democrats}
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Democrat") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Democrat") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Democrat") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Democrat") %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

iu_anti_att <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Democrat") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti_att <- iu_anti_att[2,]

or_anti_att <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Democrat") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti_att <- or_anti_att[2,]

iu_co_att <- lm_robust(data = ld3_IU %>% filter(party_3_lean=="Democrat") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co_att <- iu_co_att[2,]

or_co_att <- lm_robust(data = ld3_OR %>% filter(party_3_lean=="Democrat") %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co_att <- or_co_att[2,]

co_data <- rbind(iu_co, or_co, iu_anti, or_anti,
                 iu_co_att, or_co_att, iu_anti_att, or_anti_att)
co_data$model <- c("Co-partisan", "Co-partisan", "Out-partisan", "Out-partisan",
                   "Co-partisan Atttentive", "Co-partisan Attentive", "Out-partisan Attentive", "Out-partisan Attentive")
co_data$partisan <- rep(c("Co-partisan", "Co-partisan", "Out-partisan", "Out-partisan"), 2)
co_data$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), 2), 2)
co_data$attentive <- rep(c("Full", "Attentive Only"), each = 4)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot <- dwplot(co_data %>% arrange(partisan),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = partisan, shape = partisan)),
whisker_args = list(aes(linetype = attentive, color = partisan)))  +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"),
                        values = c(1,2),
                        na.translate = F) +
  scale_color_manual(name = "Partisanship", 
                   labels = c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   breaks=c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   values = c("#F8766D", "#00BA38", "#619CFF"),
                   na.translate = F) +
 scale_shape_manual(name = "Partisanship", 
                    labels = c("Co-partisan", "Independent", "Out-partisan"), 
                    breaks=c("Co-partisan", "Independent", "Out-partisan"),
                    values = c(15, 17, 16),
                    na.translate = F) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index by Co-partisanship \n for Democrats") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
co_plot

```


#####Figure A3: Figure 5 Results by Study
#####Table B26: Figure 5 Regression Results for Study 1
#####Table B27: Figure 5 Regression Results for Study 2
#####Table B28: Figure 5 Regression Results for Study 4
#####Table B29: Figure 5 Regression Results for Study 5
```{r fig 4 by study}
wave <- c(1, 2, 4, 5)
plot_list <- list()
for(i in wave){
ld3_IU_temp <- ld3_IU %>% filter(wave==i)
ld3_OR_temp <- ld3_OR %>% filter(wave==i)
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

iu_anti_att <- lm_robust(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti_att <- iu_anti_att[2,]

or_anti_att <- lm_robust(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti_att <- or_anti_att[2,]

iu_mod_att <- lm_robust(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod_att <- iu_mod_att[2,]

or_mod_att <- lm_robust(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod_att <- or_mod_att[2,]

iu_co_att <- lm_robust(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co_att <- iu_co_att[2,]

or_co_att <- lm_robust(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co_att <- or_co_att[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti,
                 iu_co_att, or_co_att, iu_mod_att, or_mod_att, iu_anti_att, or_anti_att)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan",
                   "Co-partisan Atttentive", "Co-partisan Attentive", "Independent Attentive", "Independent Attentive", "Out-partisan Attentive", "Out-partisan Attentive")
co_data$partisan <- rep(c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan"), 2)
co_data$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), 3), 2)
co_data$attentive <- rep(c("Full", "Attentive Only"), each = 6)

#Figure A3
plot_name <- paste("co_plot_study", i, sep="_")
plot_title <- paste("Study", i, sep=" ")
plot_list[[plot_name]] <- dwplot(co_data %>% arrange(partisan),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = partisan, shape = partisan)),
whisker_args = list(aes(linetype = attentive, color = partisan)))  +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"),
                        values = c(1,2),
                        na.translate = F) +
  scale_color_manual(name = "Partisanship", 
                   labels = c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   breaks=c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   values = c("#F8766D", "#00BA38", "#619CFF"),
                   na.translate = F) +
 scale_shape_manual(name = "Partisanship", 
                    labels = c("Co-partisan", "Independent", "Out-partisan"), 
                    breaks=c("Co-partisan", "Independent", "Out-partisan"),
                    values = c(15, 17, 16),
                    na.translate = F) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle(plot_title) +
    xlim(-.25, .75) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )

#Tables B26-B29
table_title <- paste0("Figure 5 Regression Results for Study ", i)
table_label <- paste0("tab:fig_4_study", i)
sample_list <- c("Sample", paste0("Study ", i), paste(paste0("Study ", i), "Att.", sep=" "), paste0("Study ", i), paste(paste0("Study ", i), "Att.", sep=" "))
file_path <- file.path(base_dir, paste0(paste0("Tables/fig_4_table_study", i), ".tex"))

IU_fig4 <- lm(data = ld3_IU_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
IU_fig4_att <- lm(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4_att <- lm(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, IU_fig4_att, OR_fig4, OR_fig4_att,
          se = starprep(IU_fig4, IU_fig4_att, OR_fig4, OR_fig4_att),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title=table_title,
          label=table_label,
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(sample_list),
          style="APSR",
          header=F,
          type="latex",
          out=file_path)

}

pdf(file.path(base_dir, "Figures/copartisan_coefplot_by_study.pdf"), width=12, height=9, onefile = F)
ggarrange(plot_list[[1]], plot_list[[2]], plot_list[[3]], plot_list[[4]],
          nrow=2, ncol=2, common.legend = T, legend = "bottom")
dev.off()

```

#Exploratory: Video
```{r fig 4 video by study}
wave <- c(1, 4)
plot_list <- list()
for(i in wave){
ld3_IU_temp <- ld3_IU %>% filter(wave==i)
ld3_OR_temp <- ld3_OR %>% filter(wave==i)
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU_temp %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR_temp %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU_temp %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR_temp %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU_temp %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR_temp %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

iu_anti_att <- lm_robust(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti_att <- iu_anti_att[2,]

or_anti_att <- lm_robust(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti_att <- or_anti_att[2,]

iu_mod_att <- lm_robust(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod_att <- iu_mod_att[2,]

or_mod_att <- lm_robust(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod_att <- or_mod_att[2,]

iu_co_att <- lm_robust(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co_att <- iu_co_att[2,]

or_co_att <- lm_robust(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co_att <- or_co_att[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti,
                 iu_co_att, or_co_att, iu_mod_att, or_mod_att, iu_anti_att, or_anti_att)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan",
                   "Co-partisan Atttentive", "Co-partisan Attentive", "Independent Attentive", "Independent Attentive", "Out-partisan Attentive", "Out-partisan Attentive")
co_data$partisan <- rep(c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan"), 2)
co_data$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), 3), 2)
co_data$attentive <- rep(c("Full", "Attentive Only"), each = 6)

#Create coefficient plot for heterogeneous effects by partisanship
plot_name <- paste("co_plot_study", i, sep="_")
plot_title <- paste("Study", i, sep=" ")
plot_list[[plot_name]] <- dwplot(co_data %>% arrange(partisan),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = partisan, shape = partisan)),
whisker_args = list(aes(linetype = attentive, color = partisan)))  +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"),
                        values = c(1,2),
                        na.translate = F) +
  scale_color_manual(name = "Partisanship", 
                   labels = c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   breaks=c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   values = c("#F8766D", "#00BA38", "#619CFF"),
                   na.translate = F) +
 scale_shape_manual(name = "Partisanship", 
                    labels = c("Co-partisan", "Independent", "Out-partisan"), 
                    breaks=c("Co-partisan", "Independent", "Out-partisan"),
                    values = c(15, 17, 16),
                    na.translate = F) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle(plot_title) +
    xlim(-.75, .75) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )

#Create regression table
table_title <- paste0("Figure 5 Regression Results for Video, Study ", i)
table_label <- paste0("tab:fig_4_study_video", i)
sample_list <- c("Sample", paste0("Study ", i), paste(paste0("Study ", i), "Att.", sep=" "), paste0("Study ", i), paste(paste0("Study ", i), "Att.", sep=" "))
file_path <- file.path(base_dir, paste0(paste0("Tables/fig_4_table_video_study", i), ".tex"))

IU_fig4 <- lm(data = ld3_IU_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR_temp %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
IU_fig4_att <- lm(data = ld3_IU_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4_att <- lm(data = ld3_OR_temp %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, IU_fig4_att, OR_fig4, OR_fig4_att,
          se = starprep(IU_fig4, IU_fig4_att, OR_fig4, OR_fig4_att),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title=table_title,
          label=table_label,
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(sample_list),
          style="APSR",
          header=F,
          type="latex",
          out=file_path)

}

pdf(file.path(base_dir, "Figures/copartisan_coefplot_by_study_video.pdf"), width=12, height=4.5, onefile = F)
ggarrange(plot_list[[1]], plot_list[[2]],
          nrow=1, ncol=2, common.legend = T, legend = "bottom")
dev.off()

```

#Exploratory: Studies 1, 2, and 5 Only
```{r new pooling}
#IU pooled
ld3_IU <- ld1 %>% filter(alleg_treatment != "Opp. Rally") %>% 
  mutate(wave = 1) %>% 
  dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, 
                party_3, party_3_lean, pre_party_3, pre_party_3_lean, 
                partisan, partisan_lean, pre_partisan, pre_partisan_lean,
                gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) %>% 
  rbind(
    ld2 %>% filter(alleg_treatment_1 != "Fact Check") %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 2) %>% 
      dplyr::select(support = support_exp1, belief = belief_exp1, trust = trust_exp1, belief_1,
                    media_format, wave, alleg_treatment = alleg_treatment_1, 
                    party_3, party_3_lean, pre_party_3, pre_party_3_lean,
                    partisan = partisan_1, partisan_lean = partisan_1_lean,
                    pre_partisan = pre_partisan_1, pre_partisan_lean = pre_partisan_1_lean,
                    gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)) %>%
  rbind(
    ld5 %>% filter(alleg_treatment != "Opp. Rally") %>% 
  mutate(wave = 5) %>% 
    mutate(media_format = "Text") %>%
  dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, 
                party_3, party_3_lean, pre_party_3, pre_party_3_lean, 
                partisan, partisan_lean, pre_partisan, pre_partisan_lean,
                gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) 
  )

#OR pooled
ld3_OR <- ld1 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
  mutate(wave = 1) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, 
                party_3, party_3_lean, pre_party_3, pre_party_3_lean, 
                partisan, partisan_lean, pre_partisan, pre_partisan_lean,
                gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) %>% 
  rbind(
    ld2 %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 2) %>% 
      dplyr::select(support = support_exp2,
                    media_format, wave, alleg_treatment = alleg_treatment_2, 
                    party_3, party_3_lean, pre_party_3, pre_party_3_lean,
                    partisan = partisan_2, partisan_lean = partisan_2_lean,
                    pre_partisan = pre_partisan_2, pre_partisan_lean = pre_partisan_2_lean,
                    gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)) %>%
  rbind(
    ld5 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
  mutate(wave = 5) %>% 
    mutate(media_format = "Text") %>%
  dplyr::select(support,
                media_format, wave, alleg_treatment, 
                party_3, party_3_lean, pre_party_3, pre_party_3_lean, 
                partisan, partisan_lean, pre_partisan, pre_partisan_lean,
                gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) 
  )

#Subset to attentive respondents
ld3_IU <- ld3_IU %>% filter(attentiveness==2)
ld3_OR <- ld3_OR %>% filter(attentiveness==2)
```


#####Figure A4: Study 1 - Distribution of Support (Primary Outcome) by Partisan Group
#####Figure A5: Study 4 - Distribution of Support (Primary Outcome) by Partisan Group
#####Figure A6: Study 5 - Distribution of Support (Primary Outcome) by Partisan Group
```{r support histograms}
partisans <- c(-1, 0 , 1)

#Figure A4
for (id in partisans){
  print(id)
pdf(file.path(base_dir, paste0("Figures/study1-support-distributions", id, ".pdf")), width=8.5, height=4.5) 
plot <- ld1 %>% filter(partisan== id & media_format == "Text") %>% 
     count(alleg_treatment, support_1) %>%
     group_by(alleg_treatment) %>% mutate(pct = n/sum(n)) %>% ungroup() %>%
     ggplot(aes(x = support_1, y = pct, label = scales::percent(pct)), fill = "#474747") +
     geom_col(position = "dodge", width=.6, color = "#474747") +
     geom_text(position = position_dodge(width = 0.9), vjust = -0.5) +
     facet_wrap(~alleg_treatment) +
     theme_bw() +
     theme(legend.title = element_blank(),
           panel.grid = element_blank()) +
     xlab(
    if(id == -1) {
        "Support (Out-partisans)"
    } else if(id == 0) {
        "Support (Independents)"
    } else if(id == 1){
        "Support (Co-partisans)"
    }
    ) + ylab("Percentage of Respondents") +
     scale_y_continuous(labels = scales::percent) +
     geom_vline(data = ld1 %>% filter(partisan==id & media_format == "Text") %>%
                    group_by(alleg_treatment) %>%
                    summarize(mean = mean(support_1, na.rm=T)) %>%
                    pivot_longer(-alleg_treatment) %>%
                    mutate(name = as.factor(name)),
                aes(xintercept = value), linetype=2)
print(plot)
dev.off()
}


#Figure A5
for (id in partisans){
  print(id)
pdf(file.path(base_dir, paste0("Figures/study4-support-distributions", id, ".pdf")), width=8.5, height=4.5) 
plot <- ld4 %>% filter(partisan== id & media_format == "Text") %>% 
     count(alleg_treatment, support_1) %>%
     group_by(alleg_treatment) %>% mutate(pct = n/sum(n)) %>% ungroup() %>%
     ggplot(aes(x = support_1, y = pct, label = scales::percent(pct)), fill = "#474747") +
     geom_col(position = "dodge", width=.6, color = "#474747") +
     geom_text(position = position_dodge(width = 0.9), vjust = -0.5) +
     facet_wrap(~alleg_treatment) +
     theme_bw() +
     theme(legend.title = element_blank(),
           panel.grid = element_blank()) +
     xlab(
    if(id == -1) {
        "Support (Out-partisans)"
    } else if(id == 0) {
        "Support (Independents)"
    } else if(id == 1){
        "Support (Co-partisans)"
    }
    ) + ylab("Percentage of Respondents") +
     scale_y_continuous(labels = scales::percent) +
     geom_vline(data = ld4 %>% filter(partisan==id & media_format == "Text") %>%
                    group_by(alleg_treatment) %>%
                    summarize(mean = mean(support_1, na.rm=T)) %>%
                    pivot_longer(-alleg_treatment) %>%
                    mutate(name = as.factor(name)),
                aes(xintercept = value), linetype=2)
print(plot)
dev.off()
}

#Figure A6
for (id in partisans){
  print(id)
pdf(file.path(base_dir, paste0("Figures/study5-support-distributions", id, ".pdf")), width=8.5, height=4.5) 
plot <- ld5 %>% filter(partisan== id) %>% 
     count(alleg_treatment, support_1) %>%
     group_by(alleg_treatment) %>% mutate(pct = n/sum(n)) %>% ungroup() %>%
     ggplot(aes(x = support_1, y = pct, label = scales::percent(pct)), fill = "#474747") +
     geom_col(position = "dodge", width=.6, color = "#474747") +
     geom_text(position = position_dodge(width = 0.9), vjust = -0.5) +
     facet_wrap(~alleg_treatment) +
     theme_bw() +
     theme(legend.title = element_blank(),
           panel.grid = element_blank()) +
    xlab(
    if(id == -1) {
        "Support (Out-partisans)"
    } else if(id == 0) {
        "Support (Independents)"
    } else if(id == 1){
        "Support (Co-partisans)"
    }
    ) + ylab("Percentage of Respondents") +
     scale_y_continuous(labels = scales::percent) +
     geom_vline(data = ld5 %>% filter(partisan==id) %>%
                    group_by(alleg_treatment) %>%
                    summarize(mean = mean(support_1, na.rm=T)) %>%
                    pivot_longer(-alleg_treatment) %>%
                    mutate(name = as.factor(name)),
                aes(xintercept = value), linetype=2)
print(plot)
dev.off()
}

```


#####Figure A7: "Persuasion in Parallel" Treatment Effects in Study 4
```{r persuasion in parallel}
#Figure A7
ld4_narm <- ld4 %>% filter(!is.na(alleg_treatment) & !is.na(party_3))
ld4_narm$alleg_treatment_short <- case_when(
  ld4_narm$alleg_treatment=="Control" ~ "Control",
  ld4_narm$alleg_treatment=="Info. Uncertain" ~ "IU",
  ld4_narm$alleg_treatment=="Opp. Rally" ~ "OR"
)
means <- ld4_narm %>%
  dplyr::group_by(media_format, politician, alleg_treatment_short, party_3) %>%
  summarize(avg_support = mean(support_1))
segment_data <- means %>% arrange(media_format, politician, party_3, alleg_treatment_short)
segment_data$avg_support_end <- lead(segment_data$avg_support)
segment_data$xend <- lead(segment_data$alleg_treatment_short)
segment_data <- segment_data %>% filter(alleg_treatment_short != "OR")

study4 <- ggplot(data = ld4_narm, aes(x = alleg_treatment_short, y = support_1, color = party_3)) +
  geom_jitter(aes(shape = party_3), alpha = 0.4, size = 2) +
  geom_segment(data = segment_data,
               aes(y = avg_support, yend = avg_support_end,
                   x = alleg_treatment_short, xend = xend, color = party_3),
               size = 2) +
  facet_grid(media_format ~ politician, scales = "free") +
  ggtitle("Study 4: Persuasion in Parallel") +
  xlab("Treatment") +
  ylab("Support for Politician") +
  scale_color_manual(name = "Respondent Party",
                     breaks = c("Democrat", "Independent", "Republican"),
                     labels = c("Democrat", "Independent", "Republican"),
                     values = c("blue", "gray", "red")) +
  scale_shape_manual(name = "Respondent Party",
                     breaks = c("Democrat", "Independent", "Republican"),
                     labels = c("Democrat", "Independent", "Republican"),
                     values = c(15, 16, 17))
pdf(file.path(base_dir, paste0("Figures/persuasion_in_parallel.pdf")), width=7, height=5) 
study4
dev.off()

```


#####Table B30: Figure 5 with Co-partisanship, Excluding Leaners
```{r}
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan")
co_data$model <- factor(co_data$model, levels = c("Out-partisan","Independent","Co-partisan"))
co_data$term <- rep(c("Info. Uncertain", "Opp. Rally"), 3)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot_1 <- dwplot(co_data %>% arrange(desc(model)),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = model, shape = model)),
whisker_args = list(aes(color = model)))  +
  labs(color = "Partisanship", shape = "Partisanship") +
  guides(color = guide_legend(reverse = T), shape = guide_legend(reverse = T)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Co-partisanship, Excluding Leaners") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 12), axis.text.y = element_text(size = 12),
          legend.text = element_text(size = 12), legend.title = element_text(size = 12)
          )
co_plot_1

#Table B30
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 with Co-partisanship, Excluding Leaners",
          label="tab:fig_4_co_nolean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Studies 1, 2, and 5 Att.", "Studies 1, 2, and 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_copartisanship_nolean.tex"))

```


#####Table B31: Figure 5 with Co-partisanship, Including Leaners
```{r}
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan")
co_data$model <- factor(co_data$model, levels = c("Out-partisan","Independent","Co-partisan"))
co_data$term <- rep(c("Info. Uncertain", "Opp. Rally"), 3)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot_2 <- dwplot(co_data %>% arrange(desc(model)),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = model, shape = model)),
whisker_args = list(aes(color = model)))  +
  labs(color = "Partisanship", shape = "Partisanship") +
  guides(color = guide_legend(reverse = T), shape = guide_legend(reverse = T)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Co-partisanship, Including Leaners") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 12), axis.text.y = element_text(size = 12),
          legend.text = element_text(size = 12), legend.title = element_text(size = 12)
          )
co_plot_2

#Table B31
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 with Co-partisanship, Including Leaners",
          label="tab:fig_4_co_lean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Studies 1, 2, and 5 Att.", "Studies 1, 2, and 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_copartisanship_lean.tex"))

```


#####Table B32: Figure 5 with Pre-Treatment Co-partisanship, Excluding Leaners
```{r}
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan")
co_data$model <- factor(co_data$model, levels = c("Out-partisan","Independent","Co-partisan"))
co_data$term <- rep(c("Info. Uncertain", "Opp. Rally"), 3)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot_5 <- dwplot(co_data %>% arrange(desc(model)),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = model, shape = model)),
whisker_args = list(aes(color = model)))  +
  labs(color = "Partisanship", shape = "Partisanship") +
  guides(color = guide_legend(reverse = T), shape = guide_legend(reverse = T)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Pre-Treatment Co-partisanship, Excluding Leaners") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 12), axis.text.y = element_text(size = 12),
          legend.text = element_text(size = 12), legend.title = element_text(size = 12)
          )
co_plot_5

#Table B32
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 with Pre-Treatment Co-partisanship, Excluding Leaners",
          label="tab:fig_4_pre_co_nolean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Studies 1, 2, and 5 Att.", "Studies 1, 2, and 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_pre_copartisanship_nolean.tex"))

```


#####Table B33: Figure 5 with Pre-Treatment Co-partisanship, Including Leaners
```{r}
#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan")
co_data$model <- factor(co_data$model, levels = c("Out-partisan","Independent","Co-partisan"))
co_data$term <- rep(c("Info. Uncertain", "Opp. Rally"), 3)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot_6 <- dwplot(co_data %>% arrange(desc(model)),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = model, shape = model)),
whisker_args = list(aes(color = model)))  +
  labs(color = "Partisanship", shape = "Partisanship") +
  guides(color = guide_legend(reverse = T), shape = guide_legend(reverse = T)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Pre-Treatment Co-partisanship, Including Leaners") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 12), axis.text.y = element_text(size = 12),
          legend.text = element_text(size = 12), legend.title = element_text(size = 12)
          )
co_plot_6

#Table B33
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(pre_partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 with Pre-Treatment Co-partisanship, Including Leaners",
          label="tab:fig_4_pre_co_lean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Studies 1, 2, and 5 Att.", "Studies 1, 2, and 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_pre_copartisanship_lean.tex"))

```


#####Table B34: Figure 5 with Partisanship, Excluding Leaners
```{r}
#Interact with partisan variable
iu_dem <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Democrat") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_dem <- iu_dem[2,]

or_dem <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Democrat") + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_dem <- or_dem[2,]

iu_ind <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Independent") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_ind <- iu_ind[2,]

or_ind <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Independent") + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_ind <- or_ind[2,]

iu_repub <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Republican") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_repub <- iu_repub[2,]

or_repub <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Republican") + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_repub <- or_repub[2,]

co_data <- rbind(iu_dem, or_dem, iu_ind, or_ind, iu_repub, or_repub)
co_data$model <- c("Democrat", "Democrat", "Independent", "Independent", "Republican", "Republican")
co_data$model <- factor(co_data$model, levels = c("Republican","Independent","Democrat"))
co_data$term <- rep(c("Info. Uncertain", "Opp. Rally"), 3)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot_3 <- dwplot(co_data %>% arrange(desc(model)),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = model, shape = model)),
whisker_args = list(aes(color = model)))  +
  labs(color = "Partisanship", shape = "Partisanship") +
  guides(color = guide_legend(reverse = T), shape = guide_legend(reverse = T)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Partisanship, Excluding Leaners") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 12), axis.text.y = element_text(size = 12),
          legend.text = element_text(size = 12), legend.title = element_text(size = 12)
          )
co_plot_3

#Table B34
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Independent") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3), ref="Independent") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Democrat", "Republican",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Democrat", "Info. Uncertain x Republican",
                             "Opp. Rally x Democrat", "Opp. Rally x Republican",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 with Partisanship, Excluding Leaners",
          label="tab:fig_4_part_nolean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Studies 1, 2, and 5 Att.", "Studies 1, 2, and 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_partisanship_nolean.tex"))

```


#####Table B35: Figure 5 with Partisanship, Including Leaners
```{r}
#Interact with partisan variable
iu_dem <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Democrat") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_dem <- iu_dem[2,]

or_dem <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Democrat") + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_dem <- or_dem[2,]

iu_ind <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Independent") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_ind <- iu_ind[2,]

or_ind <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Independent") + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_ind <- or_ind[2,]

iu_repub <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Republican") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_repub <- iu_repub[2,]

or_repub <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Republican") + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_repub <- or_repub[2,]

co_data <- rbind(iu_dem, or_dem, iu_ind, or_ind, iu_repub, or_repub)
co_data$model <- c("Democrat", "Democrat", "Independent", "Independent", "Republican", "Republican")
co_data$model <- factor(co_data$model, levels = c("Republican","Independent","Democrat"))
co_data$term <- rep(c("Info. Uncertain", "Opp. Rally"), 3)

#Create coefficient plot for heterogeneous effects by partisanship
co_plot_4 <- dwplot(co_data %>% arrange(desc(model)),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = model, shape = model)),
whisker_args = list(aes(color = model)))  +
  labs(color = "Partisanship", shape = "Partisanship") +
  guides(color = guide_legend(reverse = T), shape = guide_legend(reverse = T)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Partisanship, Including Leaners") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 12), axis.text.y = element_text(size = 12),
          legend.text = element_text(size = 12), legend.title = element_text(size = 12)
          )
co_plot_4

#Table B35
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Independent") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(party_3_lean), ref="Independent") + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Democrat", "Republican",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Democrat", "Info. Uncertain x Republican",
                             "Opp. Rally x Democrat", "Opp. Rally x Republican",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 with Partisanship, Including Leaners",
          label="tab:fig_4_part_lean",
          font.size="scriptsize",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Studies 1, 2, and 5 Att.", "Studies 1, 2, and 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_partisanship_lean.tex"))

```


#####Figure A8: Heterogeneous Treatment Effects by Co-Partisanship and Partisanship
```{r combo figure}
#Figure A8
pdf(file.path(base_dir, "Figures/copartisan_coefplot_combo.pdf"), width=12, height=9, onefile = F)
ggarrange(co_plot_1, co_plot_2, co_plot_5, co_plot_6, ncol=2, nrow=2, common.legend = T, legend = "bottom")
dev.off()

pdf(file.path(base_dir, "Figures/partisan_coefplot_combo.pdf"), width=12, height=4.5, onefile = F)
ggarrange(co_plot_3, co_plot_4, ncol=2, nrow=1, common.legend = T, legend = "bottom")
dev.off()

```


#####Exploratory: What is associated with the liar's dividend among opponents?
```{r explore}
opponents <- ld3_IU %>% filter(partisan==-1)
lm_robust(data = opponents,
                  support ~ alleg_treatment*media_literacy + wave + gender + race + age + income
                  +education + region + media_literacy + digital_literacy) %>% tidy()


opponents <- ld3_OR %>% filter(partisan==-1)
dig_lit <- lm_robust(data = opponents,
                  support ~ alleg_treatment*digital_literacy + wave + gender + race + age + education + income
                  + region + media_literacy + digital_literacy) %>% tidy()
dig_lit[23,]

```

